package com.wang.study.service.impl;

import com.wang.study.commons.MybatisUtils;
import com.wang.study.mapper.CartMapper;
import com.wang.study.mapper.OrderMapper;
import com.wang.study.model.Order;
import com.wang.study.service.OrderService;

import java.util.ArrayList;
import java.util.List;

public class OrderServiceImpl  implements OrderService {
    private OrderMapper orderMapper;
    private CartMapper cartMapper;
    
    public OrderServiceImpl(){
        orderMapper = MybatisUtils.getMapper(OrderMapper.class);
        cartMapper= MybatisUtils.getMapper(CartMapper.class);
    }

    /**
     * 添加订单信息，并且删除购物车信息
     * @param cid 购物车id
     * @param order 订单
     * @return
     */
    @Override
    public Integer insertOrder(ArrayList<Integer> cid, Order order) {
        Integer count1 = orderMapper.insertOrder(order);
        Integer count2 = cartMapper.delCartById2(cid);
        return (count1>0&&count2>0?count1:0);
    }

    @Override
    public Integer updateStatusById(String id) {
        return orderMapper.updateStatusById(id);
    }

    @Override
    public List<Order> showOrderByUserId(String uid) {
        return cartMapper.showOrderByUserId(uid);
    }
}
